using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ViewModelCallViewModel.Models;
using ViewModelCallViewModel.Services;

namespace ViewModelCallViewModel.ViewModels;

[ObservableObject]
public partial class MainPageViewModel {
    private readonly IPoetryService _poetryService;

    private readonly FunctionPageViewModel _functionPageViewModel;

    public MainPageViewModel(IPoetryService poetryService,
        FunctionPageViewModel functionPageViewModel) {
        _poetryService = poetryService;
        _functionPageViewModel = functionPageViewModel;
    }

    [RelayCommand]
    private void AddPoetry() {
        var id = (int)DateTime.Now.Ticks;
        var poetry = new Poetry {
            Id = id, Name = $"Name {id}", Content = $"Content {id}"
        };
        _poetryService.AddPoetry(poetry);
        _functionPageViewModel.AddPoetry(poetry);
    }
}